class Solution:
    def maxSubArray(self, nums) -> int:
        # 动态规划，原地修改数组
        maxnum = nums[0]
        for i in range(1,len(nums)):
            if nums[i - 1] > 0:
                nums[i] += nums[i - 1]
            maxnum = max(maxnum,nums[i])
            print('i:', i)
            print('max:', maxnum)
            print('nums:', nums)
        return maxnum

nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Solution().maxSubArray(nums)